package Applet;

import javax.swing.JApplet;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JToolBar;
import java.awt.Rectangle;
import javax.swing.JButton;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

public class PanelBotonMenu extends JApplet{
	
	private static final long serialVersionUID = 1L;
	
	private JToolBar jJToolBarBar = null;
	private JPanel jPanelBotonMenu = null;
	private JButton jButtonNuevo = null;
	private JButton jButtonGraba = null;
	private JButton jButtonBuscar = null;
	private JButton jButtonDelete = null;
	private JButton jButtonUpdate = null;
	private JButton jButtonExit = null;

	private FrmTipo frm = null;
	
	public PanelBotonMenu(FrmTipo oFrmTipo){
		setFrmTipo(oFrmTipo);
	}
	
	/**
	 * This method initializes jPanelBotonMenu	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	public JPanel getJPanelBotonMenu() {
		if (jPanelBotonMenu == null) {
			jPanelBotonMenu = new JPanel();
			jPanelBotonMenu.setLayout(null);
			jPanelBotonMenu.setPreferredSize(new Dimension(0, 30));
			jPanelBotonMenu.add(getJJToolBarBar(), null);
		}
		return jPanelBotonMenu;
	}

	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private JToolBar getJJToolBarBar() {
		if (jJToolBarBar == null) {
			jJToolBarBar = new JToolBar();
			jJToolBarBar.setBounds(new Rectangle(-1, 1, 190, 26));
			jJToolBarBar.add(getJButtonNuevo());
			jJToolBarBar.add(getJButtonGraba());
			jJToolBarBar.add(getJButtonBuscar());
			jJToolBarBar.add(getJButtonDelete());
			jJToolBarBar.add(getJButtonUpdate());
			jJToolBarBar.add(getJButtonExit());
		}
		return jJToolBarBar;
	}
	/**
	 * This method initializes jButtonNuevo	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonNuevo() {
		if (jButtonNuevo == null) {
			jButtonNuevo = new JButton();
			jButtonNuevo.setMnemonic(KeyEvent.VK_UNDEFINED);
			jButtonNuevo.setToolTipText("Nuevo");
			jButtonNuevo.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/New document.png")));
			jButtonNuevo.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()" + "Nuevo"); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().nuevo();
				}
			});
		}
		return jButtonNuevo;
	}

	/**
	 * This method initializes jButtonGraba	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonGraba() {
		if (jButtonGraba == null) {
			jButtonGraba = new JButton();
			jButtonGraba.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/Save.png")));
			jButtonGraba.setEnabled(false);
			jButtonGraba.setToolTipText("Grabar");
			jButtonGraba.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()" + "GRABAR"); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().grabar();
				}
			});
		}
		return jButtonGraba;
	}

	/**
	 * This method initializes jButtonBuscar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonBuscar() {
		if (jButtonBuscar == null) {
			jButtonBuscar = new JButton();
			jButtonBuscar.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/Search.png")));
			jButtonBuscar.setToolTipText("Buscar");
			jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"+"BUSCAR" ); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().buscar();
				}
			});
		}
		return jButtonBuscar;
	}

	/**
	 * This method initializes jButtonDelete	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonDelete() {
		if (jButtonDelete == null) {
			jButtonDelete = new JButton();
			jButtonDelete.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/Delete.png")));
			jButtonDelete.setEnabled(false);
			jButtonDelete.setMnemonic(KeyEvent.VK_UNDEFINED);
			jButtonDelete.setToolTipText("Borrar");
			jButtonDelete.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()" + "BORRAR"); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().delete();
				}
			});
		}
		return jButtonDelete;
	}

	/**
	 * This method initializes jButtonUpdate	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonUpdate() {
		if (jButtonUpdate == null) {
			jButtonUpdate = new JButton();
			jButtonUpdate.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/Update.png")));
			jButtonUpdate.setEnabled(false);
			jButtonUpdate.setMnemonic(KeyEvent.VK_UNDEFINED);
			jButtonUpdate.setToolTipText("Actualizar");
			jButtonUpdate.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()" + "UPDATE"); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().update();
				}
			});
		}
		return jButtonUpdate;
	}

	/**
	 * This method initializes jButtonExit	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonExit() {
		if (jButtonExit == null) {
			jButtonExit = new JButton();
			jButtonExit.setIcon(new ImageIcon(getClass().getResource("/iconos_3/16x16-free-application-icons/png/16x16/Exit.png")));
			jButtonExit.setToolTipText("Salir");
			jButtonExit.setText("");
			jButtonExit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//System.out.println("actionPerformed()" + "SALIR"); // TODO Auto-generated Event stub actionPerformed()
					getFrmTipo().salir();
				}
			});
		}
		return jButtonExit;
	}

	private void setFrmTipo(FrmTipo oFrmTipo){
		frm = oFrmTipo;
	}
	private FrmTipo getFrmTipo(){
		return frm;
	}
	public void activarDelete(boolean opcion){
		jButtonDelete.setEnabled(opcion);
	}
	public void activarUpdate(boolean opcion){
		jButtonUpdate.setEnabled(opcion);
	}
	public void activarGraba(boolean opcion){
		jButtonGraba.setEnabled(opcion);
	}
}
